

#ifndef _SERIALHMI_ANALYSIS_H_
#define _SERIALHMI_ANALYSIS_H_

#include "serialHMI_struct.h"
#include "ringbuff.h"

#define LENGTH_AT_CMD_MAX          100

#define NUM_FRAME_BUF_MAX          16
#define NUM_HMI_RECE_BUF_MAX       256

#define TIMEOUT_DATA_MONITOR       300
#define TIMEOUT_KEY_CTRL           300
#define TIMEOUT_PLOT               200
#define HMI_MINITOR_INTERVAL       1

#define HMI_MINITOR_DATA_NUM       90
#define HMI_MINITOR_DATA_MAX       90
#define HMI_MINITOR_DATA_GROUP     (HMI_MINITOR_DATA_MAX / 3)

#define HMI_MINITOR_FAULT_INDEX    132
#define HMI_MINITOR_HISTORY_INDEX  133
#define HMI_MINITOR_INDEX_MAX      134
#define HMI_MINITOR_INDEX_OFFSET   100

#define HMI_PARAM_DATA_NUM         60 
#define HMI_PARAM_DATA_MAX         90
#define HMI_PARAM_DATA_GROUP       (HMI_PARAM_DATA_MAX / 3)
#define HMI_PARAM_ADDR_OFFSET      0

#define HMI_PRODUCT_INFO_NUM         9
#define HMI_PRODUCT_INFO_INDEX       169
#define HMI_PRODUCT_INFO_INDEX_MAX   171



#define HMI_PARAM_INDEX_OFFSET     0

typedef struct
{
	
	// data monitor -----------------
	uint8_t  monitor_en;
	uint16_t monitor_cnt;
	uint16_t monitor_interval;
	uint16_t monitor_heartbeat;
	
	uint16_t monitor_data[HMI_MINITOR_DATA_MAX];
	
	uint32_t monitor_fault_now;
	uint32_t monitor_fault_his;
	
	// ctrl cmd -------------------
	uint8_t  keyctrl_en;
	uint16_t keyctrl_cnt;
	uint8_t  faultclear;
	
	// parameter read and write -----------
	uint8_t  readAll_en;	
	uint16_t monitor_param[HMI_PARAM_DATA_MAX];
	uint16_t product_info[HMI_PRODUCT_INFO_NUM];
	
	// plot data wave ---------------
	uint16_t plot_flg[HMI_MINITOR_DATA_MAX];
	uint16_t plot_timecnt[HMI_MINITOR_DATA_MAX];
	uint16_t plot_index[HMI_MINITOR_DATA_MAX];
	
}STR_HMI_HANDLE;


extern void serialHMI_init(uint16_t device_num);
extern void hmi_comm_handle(STR_RINGBUF* rece_bufhdl, STR_RINGBUF* send_bufHdl);


extern uint8_t get_hmi_keyenable(void);
extern void get_hmi_keystatus(uint8_t *datatemp, ENUM_HMI_KEY_TYPE key_type);


extern uint8_t get_hmi_faultclear(void);
extern void set_hmi_faultclear(uint8_t status);


extern void send_buf_packing(STR_RINGBUF* bufhdl, STR_HMI_FRAME* frame);






#endif


